package tech.aistar.controller.like;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.config.GuidelInterceptor;
import tech.aistar.entity.authordis.UserTable;
import tech.aistar.entity.like.NoteCodeStatus;
import tech.aistar.entity.like.NoteResult;
import tech.aistar.service.like.IPraiseService;

import javax.servlet.http.HttpSession;

/**
 * Created by lenovo on 2019/10/17.
 */
@Controller
@RequestMapping("/praise")
public class PraiseController {

    @Autowired
    private IPraiseService praiseService;

    @GuidelInterceptor
    @RequestMapping("/addPraise")
    @ResponseBody
    public NoteResult addPraise(Integer noteId, HttpSession session) {
        System.err.println("//////////////开始点赞/////////////");
        UserTable u = (UserTable) session.getAttribute("userId");
        Integer userId = u.getId();
        String num = praiseService.addPraise(noteId, userId);
//        if ("no".equals(num)){
        if ("0".equals(num)) {
//            return new NoteResult(NoteCodeStatus.ERROR, false, "今天已投");
            return new NoteResult(NoteCodeStatus.ERROR, false, "点赞已取消");
        } else {
            return new NoteResult(NoteCodeStatus.OK, true, "感谢点赞", num);
        }

    }

}
